package ar.edu.itba.it.paw.web.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import ar.edu.itba.it.paw.web.command.BuyProductForm;

@Component
public class BuyProductFormValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return BuyProductForm.class.equals(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		BuyProductForm form = (BuyProductForm) target;
		
		if(Integer.valueOf(form.getQuantity()) <= 0){
			errors.rejectValue("quantity", "invalid");
		}
	}
}
